/* eslint-disable */
class CompleteData {
  constructor() { }
  // 发货方
  shipper (_s) {
    let { customerName, showCustomerName, customerType, showCustomerType } = _s?.customer;
    let {
      provinceCode,
      districtCode,
      cityCode,
      location,
      locationType,
      ...params
    } = _s?.fromAddress;
    let obc = { ..._s?.fromContact, customerName, showCustomerName, showCustomerType, customerType, ...params };
    for (let k in obc) {
      if (k != "customerName") {
        // k首字母转大写 + 从k索引1的位置提取字符，如 address => Address
        let toUpper = k[0].toUpperCase() + k.substr(1);
        let newKey = `from${toUpper}`;
        obc[newKey] = obc[k];
      }
    }
    return obc;
  }
  // 收货方
  carrier (_s) {
    let { consigneeName } = _s?.consignee;
    let {
      provinceCode,
      districtCode,
      cityCode,
      location,
      locationType,
      ...params
    } = _s?.toAddress;
    let obc = { ..._s?.toContact, consigneeName, ...params };
    for (let k in obc) {
      if (k != "consigneeName") {
        let toUpper = k[0].toUpperCase() + k.substr(1);
        let newKey = `to${toUpper}`;
        obc[newKey] = obc[k];
      }
    }
    return obc;
  }
  redirect (data) {
    let adjustmentData = data.map((_x) => {
      return {
        contractNo: _x.contractNo,
        fromTime: _x.fromTime,
        toTime: _x.toTime,
        ...this.shipper(_x),
        ...this.carrier(_x),
        // 订单信息
        transportRequirement: _x.transportRequirement,
        waybillCache: _x.waybillCache,
        id: _x.id,
        waybillId: _x.waybillId,
        status: _x.status,
        statusDesc: _x.statusDesc,
        device: _x.device,
        totalWeight: Number(_x.waybillCache.totalWeight.toFixed(2)),
        totalVolume: Number(_x.waybillCache.totalVolume.toFixed(2)),
        calculateWeight: Number(_x.waybillCache.calculateWeight.toFixed(2)),
        calculateVolume: Number(_x.waybillCache.calculateVolume.toFixed(2)),
        calculateValue: Number(_x.waybillCache.calculateValue.toFixed(2)),
        totalQuantity: _x.waybillCache.totalQuantity,
        closeStatus: _x.closeStatus,
        billDayStatus: _x.billDayStatus,
        finance: _x.finance,
        combineNo: _x.combineNo
      };
    });
    return adjustmentData;
  }
}

const completeData = new CompleteData();

export default completeData;
